package com.jinlia.show.modules.base.model.po;

import com.jinlia.show.modules.base.system.entity.SysMenu;
import com.jinlia.show.modules.base.system.entity.SysRole;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


@Data
public class SysRolePO extends SysRole {

    //用户树模型
    private List<SysMenu> sysMenuList;

    public List<SysMenu> getSysMenuList() {
        return sysMenuList;
    }

    public void setSysMenuList(List<SysMenu> sysMenuList) {
        this.sysMenuList = sysMenuList;
        this.menuIds = sysMenuList.stream().map(SysMenu::getId).collect(Collectors.toSet());
    }

    private Set<Long> menuIds;

    public static SysRolePO fromEntity(SysRole sysUser) {
        SysRolePO sysUserVO = new SysRolePO();
        BeanUtils.copyProperties(sysUser, sysUserVO);
        return sysUserVO;
    }

    public static SysRole toEntity(SysRolePO sysUserVO) {
        SysRole sysUser = new SysRole();
        BeanUtils.copyProperties(sysUserVO, sysUser);
        return sysUser;
    }

}
